/**
 * 控制台数据统计控制器
 */
import tem from './index.html'
import G2 from 'g2'
import $_fn from '~plugins'
class chartsPieCtrl {
  constructor($scope) {
  	$scope.xinXi1=function(list){
	      var data=list.data.consolePieChart.getOrderStatusPie;
	      //百分比计算
	      var nums=0
	      if(data && data.length){
	      	for(var i=0; i<data.length; i++ ){
		      	nums+=parseInt(data[i].count)
		      }
		      for(var j=0; j<data.length;j++ ){
		      	data[j].count=data[j].count/nums
		      }
	      }
	      
	      console.log("还款监控",data)
	      var Stat = G2.Stat;
	      var chart = new G2.Chart({
	          id: 'charts_pie',
	          forceFit: true,
	          plotCfg: {
	              margin: [90, 0, 60, 0]
	          },
	          height: 450,
	      });
	      chart.source(data);
	      // 重要：绘制饼图时，必须声明 theta 坐标系
	      chart.coord('theta', {
	          radius: 0.7, // 设置饼图的大小
	          inner: 0.6
	      });
	      chart.tooltip({
	          title: null
	      });
	      chart.legend({
	          position: 'top', // 设置图例的显示位置
	          spacingX: 20,    // 图例项之间的水平间距
	          dy:20,
	          title: null,     // 不展示图例 title
	          word: {
	              fill: '#656363',
	              fontSize: 14
	          },
	      });
	      chart.intervalStack()
	          .shape('burstPie')
	          .position(Stat.summary.percent('count'))
	          .color('key', ['#f3bc30', '#689be9'])
	          .style({
	              stroke: '#fff',
	              lineWidth: 2
	          }).label('status*..percent',function(status, percent){
	          percent = (percent * 100).toFixed(2) + '%';
	          return status + ':' + percent;
	      });
	
	      chart.render();
	      // chart.on('plotclick',function(ev){
	      //     var data = ev.data;
	      //     if (data) {
	      //         var value = data._origin['value'];
	      //         var name = data._origin['key'];
	      //        $('.charts_name').text(name+':'+(value*100).toFixed(2)+'%')
	      //     }
	      // });
	      chart.on('plotleave',function(ev){
	          console.log('1')
	      })
  	}
  	$scope.kongZhiTai($scope.xinXi1) 
  }
}


chartsPieCtrl.$inject = ['$scope','$rootScope','$timeout','$location','$interval']
module.exports = angular.module('directive.chartsPie', []).directive('chartsPie', function() {
    return {
        restrict: 'E',
        template: tem,
        replace:true,
        controller: chartsPieCtrl
    }
}).name